//
// Created by hsj on 2022/2/24.
// catch：同java异常处理一致，最详细的子类放在最先部分
// 继承exception
//
#include <iostream>
#include <exception>
#include <string>
#include <cstring>
#include "../t_utils/t_utils.h"
#ifndef CLION_CPP_T_EXCEPTION_H
#define CLION_CPP_T_EXCEPTION_H
namespace t_exception_test{
    using std::cout;
    using std::cin;
    using std::endl;
    using std::string;
    using std::exception;

class BadHMean: public exception{
    private:
        double val1;
        double val2;
    public:
        BadHMean(double a = 0,double b = 0):val1(a),val2(b){}
        //exception重写的what
        virtual const char*
        what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT{
            t_utils_test::T t;
            string message;
            message.append("hmean(");
            message.append(t.double2str(val1));
            message.append(", ");
            message.append(t.double2str(val2));
            message.append("); invalid params:a == -b.");
            return message.c_str();
        }
        const char * message(){
            t_utils_test::T t;
            string message;
            message.append("hmean(");
            message.append(t.double2str(val1));
            message.append(", ");
            message.append(t.double2str(val2));
            message.append("); invalid params:a == -b.");
            return message.c_str();
        }
        virtual ~BadHMean(){}
    };


    double hmean(double a,double b);
    //测试异常
    void test();
}

#endif //CLION_CPP_T_EXCEPTION_H
